import {defineStore} from 'pinia'
import authData  from "@/mock/authData.js";

export const useAuthStore = defineStore('auth',{
    state:()=>({
        user:null,
        token:null,
        menuList:[],
        permissions:[],
        isAuthenticated:false,
        hasLoadedDynamicRoutes:false,
    }),
    actions:{
        login(user){
            this.user  = user.data.user
            this.token = user.data.token
            this.menuList = authData.data.menuList
            this.permissions = authData.data.permissions
            this.isAuthenticated = true
        },
        getUser(){

        },
        // 添加更新头像的方法
        updateAvatar(avatarUrl) {
            if (this.user) {
                this.user.avatar = avatarUrl;
            }
        },
        logout(){
            this.user = null
            this.isAuthenticated = false
            this.token = null
            this.menuList = []
            this.permissions = []
            this.hasLoadedDynamicRoutes = false
        },
        isLoggedIn(){
            return this.isAuthenticated
        }
    }
})